import {message} from 'antd';
// import {history} from '@umijs/max';
import request from '@/utils/request';

const fileModel = {
  namespace: 'files',
  state: {
    fileList: [],
    dictData: {}
  },
  effects: {
    *init(_, {call, put}){
      yield put({type: 'getDict'})
    },
    *getDict({payload},{call, put}){
      const data = yield call(() => request('/api1/new/file/getDictList', {method: 'get'})); // 仅仅为了方便查看控制台数据
      // console.log('getDict', data);
      if (data && data.code === 200){
        yield put({
          type: 'setState',
          payload: {
            dictData: data?.data || {}
          }
        })
      }
    },
    *upData({payload}, {call, put}){
      const {data = {}, code} = yield call(() => request('/api2/auth/upData', {method: 'post', data: {...payload}}));
      if (code && code === 200 && data?.userId){
        message.success('修改成功');
        setTimeout(() => {
          location.reload();
        }, 300)
      }
    }
  },
  reducers: {
    setState(state, {payload}){
      return {
        ...state,
        ...payload
      }
    }

  }
};
export default fileModel;
